package com.custom.action.core.methods.table;

import com.custom.action.core.TableInfoCache;
import com.custom.action.core.TableParseModel;
import com.custom.action.core.methods.AbstractMethod;
import com.custom.action.core.methods.MethodKind;
import com.custom.jdbc.interfaces.CustomSqlSession;
import com.custom.jdbc.interfaces.DatabaseAdapter;
import com.custom.jdbc.session.JdbcSqlSessionFactory;

/**
 * @author XiaoBai
 * @since 2024/4/17 15:54
 */
public class HasTable extends AbstractMethod {
    @Override
    protected <T> CustomSqlSession createSqlSession(JdbcSqlSessionFactory sqlSessionFactory, Class<T> target, Object[] params) throws Exception {
        return null;
    }

    @Override
    protected <T> Object doExecute(JdbcSqlSessionFactory sqlSessionFactory, Class<T> target, Object[] params) throws Exception {
        TableParseModel<T> tableModel = TableInfoCache.getTableModel(target);
        DatabaseAdapter databaseAdapter = sqlSessionFactory.getDatabaseAdapter();
        return databaseAdapter.existTable(tableModel.getTable());
    }

    @Override
    public MethodKind getKind() {
        return MethodKind.HAS_TABLE;
    }
}
